const express = require('express');
const router = express.Router();
const cozeService = require('../utils/cozeService');

// 生成教学设计
router.post('/generate', async (req, res) => {
  try {
    const { subject, topic, grade, duration, userId } = req.body;
    
    // 调用Coze智能体
    const result = await cozeService.generateTeachingDesign({
      subject,
      topic,
      grade,
      duration,
      userId
    });
    
    // 处理返回结果
    const teachingDesign = {
      id: Date.now().toString(),
      title: `${topic} - 教学设计`,
      content: result.messages[0].content,
      subject,
      grade,
      duration,
      createdAt: new Date().toISOString()
    };
    
    res.json({
      code: 200,
      data: teachingDesign,
      message: '教学设计生成成功'
    });
  } catch (error) {
    console.error('生成教学设计失败:', error);
    res.status(500).json({
      code: 500,
      message: '生成失败，请重试'
    });
  }
});

module.exports = router;